// Store.hasMany(User, { foreignKey: 'store_id', sourceKey: 'id' })
module.exports = (sequelize, DataTypes) => {
    const Store = sequelize.define(
        'Store',
        {
            id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                autoIncrement: true,
                primaryKey: true
            },
            store_no: {
                type: DataTypes.SMALLINT.UNSIGNED,
                unique: true,
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '店号不能为空'
                    },
                    min: {
                        args: 1001,
                        msg: '店号的长度必须为4位数字'
                    },
                    max: {
                        args: 9999,
                        msg: '店号的长度必须为4位数字'
                    }
                },
                comment: '店号'
            },
            name: {
                type: DataTypes.STRING(30),
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '店名不能为空'
                    }
                },
                comment: '店名'
            },
            address: {
                type: DataTypes.STRING(50),
                allowNull: true,
                comment: '地址'
            },
            start_business: {
                type: DataTypes.DATEONLY,
                allowNull: true,
                validate: {
                    isDate: {
                        args: true,
                        msg: '开店日期必须是一个日期格式'
                    }
                },
                comment: '开店日期'
            }
        },
        {
            tableName: 'store'
        }
    )

    return Store
}
